/**
 * Created by Administrator on 2015/12/15.
 */

/**
 * Created by Administrator on 2015/12/14.
 */

var express = require('express');
var router = express.Router();
var BaseModel = require('../models/base_model');
var baseModel = new BaseModel();
var CheckLogin = require('../models/checkLogin');
var checkLogin =new CheckLogin();

router.get('/',checkLogin.check);

router.get('/', function(req, res) {
    res.render('great_ip',{
        title:'生成IP地址池',
        cook_name:req.cookies.IP
    });
});

router.post('/',checkLogin.check);

router.post('/',function(req,res) {
    var tableName = 'ips';
    var rowInfo = {};
    var c_Lan = req.body.ip1 + '.' + req.body.ip2 + '.' + req.body.ip3;
    for (var i = 1; i <= 255; i++) {
        rowInfo = {
            'ip_name': c_Lan + '.' + i,
            'c_lan': c_Lan,
            'states':'未用'
        };
        baseModel.insert(tableName, rowInfo, function (ret) {
        })
    }
    var sql = "select * from ips where c_Lan='" + c_Lan + "'";
    baseModel.findMoreById(sql, function (ret) {
        res.render('great_ip', {
            title: '主页',
            content: ret,
            cook_name: req.cookies.IP
        });
    });
})

module.exports = router;
